package ru.spb.nicetu.schoolproject.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by dchernyshov on 01.04.15.
 */
public class MainFrame extends JFrame {
    private Box hbox1;
    private Box hbox2;
    private Box vbox;

    private JButton listOfTeachers;
    private JButton listOfClasses;
    private JButton listOfPupils;
    private JButton listOfMarks;
    private JButton listOfLessons;


    public MainFrame() {
        setFrameSize();
        vbox = createVerticalBox();
    }

    public void setFrameSize() {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        setSize(screenWidth / 4, screenHeight / 8);
        setLocationByPlatform(true);
    }

    public Box createFirstHorizontalBox() {
        Box box1 = Box.createHorizontalBox();
        createListOfTeachersButton();
        box1.add(listOfTeachers);
        box1.add(Box.createHorizontalStrut(20));
        createListOfClassesButton();
        box1.add(listOfClasses);
        return box1;
    }

    public Box createSecondHorizontalBox() {
        Box box2 = Box.createHorizontalBox();
        createListOfPupilsButton();
        box2.add(listOfPupils);
        box2.add(Box.createHorizontalStrut(20));
        createListOfMarksButton();
        box2.add(listOfMarks);
        box2.add(Box.createHorizontalStrut(20));
        createListOfLessonsButton();
        box2.add(listOfLessons);
        return box2;
    }

    public Box createVerticalBox() {
        Box box = Box.createVerticalBox();
        hbox1 = createFirstHorizontalBox();
        box.add(hbox1);
        box.add(Box.createVerticalStrut(10));
        hbox2 = createSecondHorizontalBox();
        box.add(hbox2);
        box.add(Box.createVerticalGlue());
        add(box, BorderLayout.CENTER);
        return box;
    }

    public void createListOfTeachersButton() {
        listOfTeachers = new JButton("Учителя");
        listOfTeachers.addActionListener(new ListOfTeachersListener());
    }

    public void createListOfClassesButton() {
        listOfClasses = new JButton("Классы");
        listOfClasses.addActionListener(new ListOfClassesListener());
    }

    public void createListOfPupilsButton() {
        listOfPupils = new JButton("Ученики");
        listOfPupils.addActionListener(new ListOfPupilsListener());
    }

    public void createListOfMarksButton() {
        listOfMarks = new JButton("Отметки");
        listOfMarks.addActionListener(new ListOfMarksListener());
    }

    public void createListOfLessonsButton() {
        listOfLessons = new JButton("Уроки");
        listOfLessons.addActionListener(new ListOfLessonsListener());
    }

    public class ListOfTeachersListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JDialog dialog = new ListOfTeachersFrame();
            dialog.setVisible(true);
        }
    }

    public class ListOfClassesListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JDialog dialog = new ListOfClassesFrame();
            dialog.setVisible(true);
        }
    }

    public class ListOfPupilsListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JDialog dialog = new ListOfPupilsFrame();
            dialog.setVisible(true);
        }
    }

    public class ListOfMarksListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JDialog dialog = new MarkFrame();
            dialog.setVisible(true);
        }
    }

    public class ListOfLessonsListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JDialog dialog = new ListOfLessonFrame();
            dialog.setVisible(true);
        }
    }
}
